﻿var min = /*min*/; // ignore syntax errors, values changed in proper method
var max = /*max*/;
var round = 0;
var values = [/*values*/];

Number.prototype.round = function (places) {
    places = Math.pow(10, places);
    return Math.round(this * places) / places;
};

function RotateSVG() {
    var height = 250;
    var width = 250;

    var angle = 0;
    var range = (max - min);
    var direction = 1;
    var animator = null;
    if (animator != null) {
        clearInterval(animator);
        animator = null;
        return;
    }
    var loop = 0;
    var rangespaced = values[loop + 1] - values[loop];
    var offset = values[loop];
    animator = setInterval(
        function() {
            angle += 1 / 33 * direction;
            if (angle >= 1) {
                loop += direction;
                if (loop + 1 >= values.length) {
                    loop = 0;
                    rangespaced = values[values.length - 1] - values[0];
                    console.log(values[values.length - 1]);
                    direction = -1;
                    offset = values[values.length - 1];
                } else {
                    rangespaced = values[loop + 1] - values[loop];
                    offset = values[loop];
                }
                angle = 0;
            } else if (angle < -1) {
                console.log("change");
                direction = 1;
                offset = values[0];
                loop = 0;
                rangespaced = values[loop + 1] - values[loop];
                angle = 0;
            }
            var value = window["EasingFunctions"]["/*easingMethod*/"](Math.abs(angle)); //variable changed
            var calculatedValue = rangespaced * value * direction + offset;
            value *= 268 * (rangespaced / range) * direction;
            value += 268 * (offset / range);
            $("polygon").attr("transform", "rotate(" + value + " " + height + " " + width + ")");
            $("text").last().text(calculatedValue.round(round));
        }, 33);
}

if (values.length > 1) {
    RotateSVG();
}